// pages/my/my.js
var common = require("../../public");
var url = common.url;
var APP_ID = common.APP_ID;
var md5 = common.md5Start;
Page({

  /**
   * 页面的初始数据
   */
  data: {
	  showmask:false,//是否显示 签到 弹框   true：显示    false：隐藏
	  signArr:[
		  { issign: true, img: 1, title: '10个积分' },
		  { issign: false, img: 1, title: '10个积分' },
		  { issign: false, img: 1, title: '10个积分' },
		  { issign: false, img: 1, title: '10个积分' },
		  { issign: false, img: 1, title: '10个积分' },
		  { issign: false, img: 1, title: '10个积分' },
		  { issign: false, img: 1, title: '10个积分' },
	  ]
  },
  //跳转拍卖中页面
	go_paimaiing:function(e){
		wx.navigateTo({
			url: '../paimaiing/paimaiing',
		})
	},
  //go_orderlist  跳转到订单列表页面
	go_orderlist:function(e){
		var num = e.currentTarget.dataset.num;
		console.log(num)
		wx.navigateTo({
			url: '../orderlist/orderlist?num='+num,
		})
	},
  //跳转道具页面
	go_daoju:function(e){
		wx.navigateTo({
			url: '../daoju/daoju',
		})
	},
  //跳转钱包页面
	go_qianbao:function(e){
		wx.navigateTo({
			url: '../qianbao/qianbao'
		})
	},
  //跳转积分页面
	goJifen:function(e){
		wx.navigateTo({
			url: '../jifen/jifen'
		})
	},
  //跳转我的订单
  myorderlist:function(e){
	  wx.navigateTo({
		  url: '../orderlist/orderlist'
	  })
  },
  //跳转售后服务
	goShouhou:function(e){
		wx.navigateTo({
			url: '../shfw/shfw'
		})
	},
  //跳转我的收藏列表
	goCollection:function(e){
		wx.navigateTo({
			url: '../collection/collection'
		})
	},
  //消息列表
	gomsglist:function(e){
		wx.navigateTo({
			url: '../msglist/msglist'
		})
	},
	//签到事件
	signin_tap: function (e) {
		var that = this;
		var session_str = wx.getStorageSync('session_str');//密钥
		wx.showLoading({
			title: '加载中',
			mask: true,
		})
		wx.request({
			url: url + 'User/signin',
			data: {
				session_str: session_str,
				APP_ID: APP_ID,
				sign: md5([
					"session_str" + session_str,
					"APP_ID" + APP_ID,
				])
			},
			header: {},
			method: 'post',
			dataType: 'json',
			responseType: 'text',
			success: function (res) {
				wx.hideLoading();
				if (res.data.code == 200) {
					wx.showToast({
						title: '签到成功',
						icon: 'success',
						mask: true,
					})
					that.showmask_sign();
					that.userinfoFunction();
				} else {
					wx.showToast({
						title: res.data.msg,
						icon: 'none',
						mask: true,
					})
				}

			},
			fail: function (res) {
				wx.hideLoading();
				wx.showToast({
					title: '网络错误',
					icon: 'none',
					mask: true,
				})
			}
		});
	},
  //显示签到弹框
	showmask_sign:function(e){
		var that = this;
		var session_str = wx.getStorageSync('session_str');//密钥
		wx.showLoading({
			title: '加载中',
			mask: true,
		})
		//请求签到详情接口
		wx.request({
			url: url + 'User/signinLog',
			data: {
				session_str: session_str,
				APP_ID: APP_ID,
				sign: md5([
					"session_str" + session_str,
					"APP_ID" + APP_ID,
				])
			},
			header: {},
			method: 'post',
			dataType: 'json',
			responseType: 'text',
			success: function (res) {
				wx.hideLoading();
				if (res.data.code == 200) {
					console.log(res)
					that.setData({
						signArr: res.data.data.list,
						today_is_signin: res.data.data.today_is_signin,//今日是否签到 true：是
					})
				} else {
					wx.showToast({
						title: res.data.msg,
						icon: 'none',
						mask: true,
					})
				}

			},
			fail: function (res) {
				wx.hideLoading();
				wx.showToast({
					title: '网络错误',
					icon: 'none',
					mask: true,
				})
			}
		});
		that.setData({
			showmask: true
		})
	},
  //关闭签到弹框
	closemask:function(e){
		this.setData({
			showmask:false
		})
	},
  //跳转常见问题
	go_cjwt:function(e){
		wx.navigateTo({
			url: '../changjianwenti/changjianwenti',
		})
	},
	//跳转设置
	go_setting: function (e) {
		wx.navigateTo({
			url: '../setting/setting',
		})
	},
	// 、、获取用户信息的函数
	userinfoFunction:function(e){
		var that = this;
		var session_str = wx.getStorageSync('session_str');
		if (!session_str) {
			wx.navigateTo({
				url: '../author/author'
			})
		} else {
			//请求接口，获取用户信息
			wx.request({
				url: url + 'User/getUserInfo',
				data: {
					session_str: session_str,
					APP_ID: APP_ID,
					sign: md5([
						"session_str" + session_str,
						"APP_ID" + APP_ID
					])
				},
				header: {},
				method: 'post',
				dataType: 'json',
				responseType: 'text',
				success: function (res) {
					console.log(res)
					that.setData({
						userinfo: res.data.data
					})
				},
				fail: function (res) {

				}
			});
		}
	},

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
	  
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
	  var that = this;
	  that.userinfoFunction();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

})